﻿using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;


namespace Wayloop.Web.Mvc.Extensions
{
    public static class HtmlExtensions
    {
        /// <summary>
        /// Returns an anchor tag containing the virtual path to the specified action and area.
        /// </summary>
        /// <param name="html">The <see cref="HtmlHelper"/> instance.</param>
        /// <param name="linkText">The inner text of the anchor tag.</param>
        /// <param name="actionName">The name of the action.</param>
        /// <param name="controllerName">The name of the controller.</param>
        /// <param name="areaName">The name of the area.</param>
        /// <returns>An anchor tag containing the virtual path to the specified action and area.</returns>
        public static string ActionLink(this HtmlHelper html, string linkText, string actionName, string controllerName, string areaName)
        {
            return ActionLink(html, linkText, actionName, controllerName, areaName, null);
        }


        /// <summary>
        /// Returns an anchor tag containing the virtual path to the specified action and area.
        /// </summary>
        /// <param name="html">The <see cref="HtmlHelper"/> instance.</param>
        /// <param name="linkText">The inner text of the anchor tag.</param>
        /// <param name="actionName">The name of the action.</param>
        /// <param name="controllerName">The name of the controller.</param>
        /// <param name="areaName">The name of the area.</param>
        /// <param name="routeValues">The route values.</param>
        /// <returns>An anchor tag containing the virtual path to the specified action and area.</returns>
        public static string ActionLink(this HtmlHelper html, string linkText, string actionName, string controllerName, string areaName, object routeValues)
        {
            var combinedRouteValues = new RouteValueDictionary(routeValues) { { "area", areaName } };
            return html.ActionLink(linkText, actionName, controllerName, combinedRouteValues, null);
        }
    }
}